package com.edu.shop.controller;

import com.edu.shop.service.UserService;
import com.edu.shp.entity.User;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    // 注册 POST 请求
    /**
     * 新增
     * @param
     * @return
     */
    @PostMapping("/add")
    public String add(@RequestBody @Valid User user) {
        User usersInfo = new User();
        int register = userService.register(usersInfo);
        if (register == 1) {
            return "注册成功";
        }
        return "注册失败";
    }

    @GetMapping("/get")
    public User get(Integer id) {
        User user = userService.findById(id);
        return user;
    }



}
